using System;
using System.Collections;
using UnityEngine;
using Voodoo.Sauce.Core;

namespace Voodoo.Sauce.Internal.Analytics
{
	public class PerformanceMetricsManager
	{
		private static bool _applicationUnpaused;

		public static void Initialize(float period)
		{
			VoodooSauceBehaviour.InvokeCoroutine(new PerformanceMetricsManager().PerformanceMetricsCoroutine(period));
		}

		internal static void OnApplicationPause(bool pauseStatus)
		{
			if (!pauseStatus)
			{
				_applicationUnpaused = true;
			}
		}

		private IEnumerator PerformanceMetricsCoroutine(float period)
		{
			float timer = 0f;
			float minMs = 99f;
			float maxMs = 0f;
			float numFrames = 0f;
			int badFrames = 0;
			int terribleFrames = 0;
			while (true)
			{
				yield return null;
				float unscaledDeltaTime = Time.unscaledDeltaTime;
				if (_applicationUnpaused)
				{
					_applicationUnpaused = false;
					continue;
				}
				timer += unscaledDeltaTime;
				minMs = Math.Min(minMs, unscaledDeltaTime);
				maxMs = Math.Max(maxMs, unscaledDeltaTime);
				numFrames += 1f;
				if (unscaledDeltaTime > 0.050000004f)
				{
					badFrames++;
				}
				if (unscaledDeltaTime > 1f / 6f)
				{
					terribleFrames++;
				}
				if (timer >= period)
				{
					SendPerformanceMetricsEvent(minMs, maxMs, numFrames / period, badFrames, terribleFrames, GC.GetTotalMemory(forceFullCollection: false));
					timer = 0f;
					numFrames = 0f;
					minMs = 99f;
					maxMs = 0f;
					badFrames = 0;
					terribleFrames = 0;
				}
			}
		}

		private void SendPerformanceMetricsEvent(float minMs, float maxMs, float aveFPS, int badFrames, int terribleFrames, long memoryUsed)
		{
		}
	}
}
